package com.xmb.wechat.delegate;

import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.squareup.picasso.Picasso;
import com.xmb.wechat.R;
import com.xmb.wechat.baserecyclerview.BaseRecyclerViewManager;
import com.xmb.wechat.common.Constant;
import com.xmb.wechat.entity.GroupCallEntity;

import java.util.ArrayList;

/**
 * @Author lijiangop
 * @CreateTime 2020/4/29 17:44
 */
public class GroupCallDetailDelegate extends BaseRecyclerViewManager {

    public GroupCallDetailDelegate(Activity activity) {
        super(activity);
    }

    @Override
    public BaseQuickAdapter initAdapter() {
        return new BaseQuickAdapter<GroupCallEntity, BaseViewHolder>(R.layout.item_group_call_detail, new ArrayList<>()) {
            @Override
            protected void convert(BaseViewHolder helper, GroupCallEntity item) {
                ImageView imageView = helper.getView(R.id.iv_avatar);
                switch (item.getAvatarSrc()) {
                    case Constant.SourceType.AVATAR_SRC_SDCARD:
                        Picasso.get().load("file://" + item.getAvatar()).error(R.drawable.ic_wx_default_avatar).into(imageView);
                        break;
                    case Constant.SourceType.AVATAR_SRC_APP_INNER_ASSETS:
                        Picasso.get().load("file:///android_asset/avatars/" + item.getAvatar()).error(R.drawable.ic_wx_default_avatar).into(imageView);
                        break;
                }
                switch (item.getState()) {
                    case 0:
                        helper.setVisible(R.id.iv_on_talk, false);
                        break;
                    case 1:
                        helper.setVisible(R.id.v_state, false);
                        helper.setVisible(R.id.iv_animation, false);
                        helper.setVisible(R.id.iv_on_talk, false);
                        break;
                    case 2:
                        helper.setVisible(R.id.v_state, false);
                        helper.setVisible(R.id.iv_animation, false);
                        break;
                }
            }
        };
    }

    @Override
    protected RecyclerView.ItemDecoration getItenDecoration() {
        return null;
    }

    @Override
    protected RecyclerView.LayoutManager getLayoutManager() {
        return new GridLayoutManager(context, 2);
    }
}
